/* eslint-disable react/prop-types */
import React from 'react';
import { Table } from 'antd';
import ToolsForm from './toolsForm'
import HandleBtns from './handleBtns'
import '@/pages/mysite/default_table.scss';
import { Empty } from 'antd';

class BaseTable extends React.Component {
    static defaultProps = {
        columns: [],
        data: []
    }

    constructor(props) {
        super(props)
        this.state = {
            selectRows: []
        }
    }

    render() {
        const { columns, data, tools, btns, batch, select, handleRow } = this.props;
        const rowSelection = {
            onChange: (selectedRowKeys, selectedRows) => {
                handleRow('selectRow', selectedRows)
            }
        };
        return (<div className="table_box">
            <ToolsForm tools={tools} handleRow={handleRow}></ToolsForm>
            {data.length > 0 ?
                <Table columns={columns}
                    dataSource={data}
                    bordered
                    size={"middle"}
                    defaultExpandAllRows
                    scroll={{ x: 1000 }}
                    rowSelection={select ? rowSelection : null}
                    rowKey="id"
                    title={() => {
                        return <HandleBtns btns={btns} batch={batch}></HandleBtns>
                    }}
                    pagination={false} /> :
                <React.Fragment>
                    <HandleBtns btns={btns} batch={batch}></HandleBtns>
                    <Empty />
                </React.Fragment>}
        </div>)
    }
}

export default BaseTable
